package main.od;

import java.util.*;
import java.util.stream.Collectors;

public class VlanTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String [] strArr = scanner.nextLine().split(",");
        String remove = scanner.nextLine();
        List<String> list = new ArrayList<>();
        for (String str : strArr){
            if (str.contains("-")){
                int start = Integer.parseInt(str.split("-")[0]);
                int end = Integer.parseInt(str.split("-")[1]);
                for (int i = start;i <= end;i++){
                    list.add(String.valueOf(i));
                }
            }else {
                list.add(str);
            }
        }
        list.remove(remove);
        //1245 7
        List<String> returnList = new ArrayList<>();
        List<Integer> inputList = list.stream().map(Integer::parseInt)
                .sorted(Comparator.comparingInt(o -> o)).collect(Collectors.toList());
        int left = inputList.get(0);
        int right = left;
        for (int i = 1;i < inputList.size();i++){
            int value = inputList.get(i);
            if (value == right + 1){
                right = value;
            }else {
                if (left == right){
                    returnList.add(String.valueOf(left));
                }else {
                    returnList.add(left + "-" + right);
                }
                left = right = value;
            }
        }
        if (left == right){
            returnList.add(String.valueOf(left));
        }else {
            returnList.add(left + "-" + right);
        }
        StringBuilder outputStr = new StringBuilder();
        returnList.forEach(s -> {
            outputStr.append(s).append(",");
        });
        System.out.println(outputStr.substring(0,outputStr.length() - 1));;
    }

}
